package traffic.light.simulator.util;

import traffic.light.simulator.town.Town;

/**
 *
 * 
 */

public class Time
        implements java.awt.event.ActionListener {

    //javax.swing.Timer remplace l'utilisation directe de thread. 
    //Ca génère un évènement à intervalles réguliers.
    //Nous l'utilisons ici pour le timer des feux de signalisation.
    private javax.swing.Timer timer;
    public static int DELAY = 10;
    private Town town;
    private boolean paused;

    @Override
    public void actionPerformed(java.awt.event.ActionEvent e) {
        //Mise a jour de la ville.
        town.update();
    }

    public Time(Town t) {
        town = t;
        timer = new javax.swing.Timer(DELAY, this);
        paused = true;
    }

    public void run() {
        timer.start();
        paused = false;
    }

    public void pause() {
        timer.stop();
        paused = true;
    }

    public void restart() {
        timer.restart();
        paused = false;
    }

    public boolean isPaused() {
        return paused;
    }
}
